package ai.zixing.mashibing.new_class.class04;

public class Code01_ReverseList {
    public static void main(String[] args) {
        Node n1 = new Node(1);
        n1.next = new Node(2);
        n1.next.next = new Node(3);
    }

    public static class Node {
        public int value;
        public Node next;
        public Node(int value) {
            this.value = value;
        }
    }

    public static class DoubleNode {
        public int value;
        public DoubleNode last;
        public DoubleNode next;
        public DoubleNode(int value) {
            this.value = value;
        }
    }

    public static Node reverseNode(Node head) {
        Node pre = null;
        Node temp = null;
        while (head != null) {
            temp = head.next;
            head.next = pre;
            pre = head;
            head = temp;
        }
        return pre;
    }

    public static DoubleNode doubleNode(DoubleNode head) {
        DoubleNode pre = null;
        DoubleNode temp = null;
        while (head != null) {
            temp = head.next;
            head.next = pre;
            head.last = temp;
            pre = head;
            head = temp;
        }
        return pre;
    }
}
